import { getCartListAsync, getCartIsChecked } from '../../api/cart'


import { defineStore } from 'pinia'

export const userShopCartData = defineStore('shopCart', {
  state: () => {
    return {
      cartList: []
    }
  },
  actions: {
    // 1、获取购物上商品列表
    async shopCartData() {
      // window.localStorage.setItem('userTempId', "c5800700-444c-4b51-bbfe-6375182d6676")


      const result: any = await getCartListAsync()
      // console.log('pinia', (result[0] || {}).cartInfoList)
      // console.log('result', result)
      this.cartList = (result[0] || {}).cartInfoList
    },

    // 2、更改购物车商品选中状态
    // async changeCartIsChecked(cartID: number, isChecked: any) {
    //   isChecked = 1 - isChecked
    //   const result: any = await getCartIsChecked(cartID, isChecked)
    //   if (result.code === 200) {
    //     alert('状态发生变化了')
    //   } else {
    //     alert('错误')
    //   }
    //   console.log(result)
    // }

  },
  getters: {
    cartList1(state) {
      return state.cartList
    }
  }
})